package svmc.stp.hoaitt;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Lake {
	static int N;
	static int T;
	
	public static void main(String[] args) throws FileNotFoundException {
		System.setIn(new FileInputStream("res/input_lake.txt"));
		Scanner sc = new Scanner(System.in);
		
		T = sc.nextInt();
		int Answer;
		for (int test_cast = 1; test_cast <= T; test_cast++) {
			N = sc.nextInt();
			int[][] input = new int[N][N];
			Answer = 0;
			
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					input[i][j] = sc.nextInt();
				}
			}
			
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					int up = 1;
					int down = 1;
					int left = 1;
					int right = 1;
					int min = 0;
					
					if (input[i][j] == 1) {
						for (int j2 = j-1; j2 > 0; j2--) {
							if (input[i][j2] == 1) {
								left++;
							} else break;
						}
						
						for (int k = i-1; k > 0; k--) {
							if (input[k][j] == 1) {
								up++;
							} else break;
						}
						
						for (int k = j+1; k < N; k++) {
							if (input[i][k] == 1) {
								right++;
							} else break;
						}
						
						for (int k = i+1; k < N; k++) {
							if (input[k][j] == 1) {
								down++;
							} else break;
						}
						
						int min1 = (up < down) ? up : down;
						int min2 = (left < right) ? left : right;
						min = min1 < min2 ? min1 : min2;
						Answer += min;
					}
				}
				
			}
			
			System.out.println("#"+test_cast+" "+Answer);
		}
		
		sc.close();
	}

}
